﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using LD24.Helpers;

namespace LD24.Entities
{
    public class Camera
    {
        private float _zoom;
        private Matrix _transform;
        public Vector2 Position;
        private float _rotation;

        public Camera()
        {
            _zoom = 1;
            _rotation = 0;
            Position = Vector2.Zero;
        }

        public float Zoom
        {
            get { return _zoom; }
            set { _zoom = value; if (_zoom > 0.1f) _zoom = 0.1f; }
        }

        public float Rotation
        {
            get { return _rotation; }
            set { _rotation = value; }
        }

        public void Move(Vector2 moveOf)
        {
            Position += moveOf;
        }

        public Matrix getTransformation(GraphicsDevice graphicsDevice)
        {
            _transform = Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
                         Matrix.CreateRotationZ(Rotation) *
                         Matrix.CreateScale(new Vector3(_zoom, _zoom, 1));

            return _transform;
        }


        public void Update()
        {
            if (KeyboardHelper.isKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
                Move(new Vector2(-5, 0));

            if (KeyboardHelper.isKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
                Move(new Vector2(5, 0));

            if (KeyboardHelper.isKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
                Move(new Vector2(0, -5));

            if (KeyboardHelper.isKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
                Move(new Vector2(0, 5));
        }
    }
}
